const api = require("../../utils/api")
const getwxphone = require("../../utils/getwxphone")
Page({

  /**
   * 页面的初始数据
   */
  data: {
    eduList: ['专科', '本科', '研究生'],
    fixed: 1,
    animation: '',
    login: !1
  },
  //点击选择-学历edu
  choiseEdu() {
    var _ = this;
    _.setData({
      bindedu: 1,
    })
  },
  //点击选择-学历edu
  setedu(e) {
    var _ = this;
    console.log(e.currentTarget.dataset.edu)
    _.setData({
      edu: e.currentTarget.dataset.edu,
      bindedu: !1
    })
  },
  //点击选择-学历edu
  choiseMajor() {
    var _ = this;
    if (_.data.edu) {
      _.setData({
        bindmajor: 1,
      })
      _.xuekemenlei()
    } else {
      wx.showToast({
        title: '请先选择学历',
        icon: 'none'
      })
    }

  },
  //2级联动-学科门类
  xuekemenlei() {
    var _ = this;
    wx.request({ //发送请求
      url: 'https://zg99.offcn.com/index/chaxun/getlevel?actid=52770&callback=?', //接收url
      data: {
        level: '2',
        grfiled: 'xueli',
        grtext: _.data.edu
      }, //接收参数
      success(res) { //返回
        var jsonStr = res.data;
        jsonStr = jsonStr.replace("(", "");
        jsonStr = jsonStr.replace(")", "");
        if (typeof jsonStr != 'object') {
          jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
          var theJson = JSON.parse(jsonStr);
        }
        // console.log(theJson)
        var list = [];
        for (var i in theJson.lists) { //循环写入下来框
          list.push(theJson.lists[i].xuekemenlei)
        }
        console.log(list)
        _.setData({
          xuekemenleiList: list
        });
      }
    })
  },
  //点击选择-学科门类xuekemenlei
  setxuekemenlei(e) {
    var _ = this;
    console.log(e.currentTarget.dataset.xuekemenlei)
    _.setData({
      xuekemenlei: e.currentTarget.dataset.xuekemenlei,
    })
    _.zhuanyeleibie();
  },
  //点击重新选择-学科门类xuekemenlei
  rechoisexuekemenlei() {
    var _ = this;
    _.setData({
      zhuanyeleibieList: !1,
      zhuanyemingchengList: !1,
      zhuanyeleibie: !1
    })
  },
  //3级联动-专业类别
  zhuanyeleibie() {
    var _ = this;
    wx.request({ //发送请求
      url: 'https://zg99.offcn.com/index/chaxun/getlevel?actid=52770&callback=?', //接收url
      data: {
        level: '3',
        grfiled: 'xuekemenlei',
        grtext: _.data.xuekemenlei,
        onefiled: 'xueli',
        onetext: _.data.edu
      }, //接收参数
      success(res) {
        var jsonStr = res.data;
        jsonStr = jsonStr.replace("(", "");
        jsonStr = jsonStr.replace(")", "");
        if (typeof jsonStr != 'object') {
          jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
          var theJson = JSON.parse(jsonStr);
        }
        var list = [];
        for (var i in theJson.lists) { //循环写入下来框
          list.push(theJson.lists[i].zhuanyeleibie)
        }
        console.log(list)
        _.setData({
          zhuanyeleibieList: list
        });
      }
    })
  },
  //点击选择-专业类别zhuanyeleibie
  setzhuanyeleibie(e) {
    var _ = this;
    console.log(e.currentTarget.dataset.zhuanyeleibie)
    _.setData({
      zhuanyeleibie: e.currentTarget.dataset.zhuanyeleibie,

    })
    _.zhuanyemingcheng()
  },
  //点击重新选择-专业类别zhuanyeleibie
  rechoisezhuanyeleibie() {
    var _ = this;
    _.setData({
      zhuanyemingchengList: !1,
      zhuanyemingcheng: !1
    })
  },
  //4级联动-专业名称
  zhuanyemingcheng() {
    var _ = this;
    wx.request({ //发送请求
      url: 'https://zg99.offcn.com/index/chaxun/getlevel?actid=52770&callback=?', //接收url
      data: {
        level: '4',
        grfiled: 'zhuanyeleibie',
        grtext: _.data.zhuanyeleibie,
        onefiled: 'xueli',
        onetext: _.data.edu,
        twofiled: 'xuekemenlei',
        twotext: _.data.xuekemenlei,
      }, //接收参数
      success(res) {
        var jsonStr = res.data;
        jsonStr = jsonStr.replace("(", "");
        jsonStr = jsonStr.replace(")", "");
        if (typeof jsonStr != 'object') {
          jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
          var theJson = JSON.parse(jsonStr);
        }
        var list = [];
        console.log(theJson)
        for (var i in theJson.lists) { //循环写入下来框
          list.push(theJson.lists[i].zhuanyemingcheng)
        }
        console.log(list)
        _.setData({
          zhuanyemingchengList: list
        });
      }
    })
  },
  //点击选择-专业名称zhuanyemingcheng
  setzhuanyemingcheng(e) {
    var _ = this;
    console.log(e.currentTarget.dataset.zhuanyemingcheng)
    _.setData({
      zhuanyemingcheng: e.currentTarget.dataset.zhuanyemingcheng,
      bindmajor: !1
    })
  },
  closeselect() {
    var _ = this;
    _.setData({
      bindEdu: !1,
      bindmajor: !1,
    })
  },

  getPhoneNumber(e) {
    var _ = this;
    console.log(e)
    const info = {
      area: wx.getStorageSync('area'),
      agent: wx.getStorageSync('agent'),
      page: wx.getStorageSync('page'),
      activeId: 32
    }

    getwxphone(e.detail.code, 52770, 'chaxun', info)
      .then(res => {
        console.log(res);
        _.setData({
          login: !1
        })
      })
      .catch(err => {
        console.log(err);
      })
  },
  xz: function (e) {
    var _ = this;
    var flag = e.detail.value[0];
    if (flag == undefined) {
      flag = false
    } else {
      flag = true
    }
    _.setData({
      flag
    })
    console.log(_.data.flag)
  },
  xy: function (e) {
    var _ = this;
    wx.navigateTo({
      url: '../agreement/agreement',
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    api.load(options)
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {},
  searchList(event) {
    var _ = this;
    var inputVal = (event.detail.value).replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g, "\\$&");
    console.log(inputVal)
    wx.request({ //发送请求
      url: 'https://zg99.offcn.com/index/chaxun/getlist?actid=52770&callback=?', //接收url
      data: {
        xueli: _.data.edu,
        zhuanyemingcheng: inputVal,
        limits: 200
      }, //接收参数
      success(res) {
        var jsonStr = res.data;
        jsonStr = jsonStr.replace("(", "");
        jsonStr = jsonStr.replace(")", "");
        if (typeof jsonStr != 'object') {
          jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
          var theJson = JSON.parse(jsonStr);
        }
        var list = [];
        console.log(theJson)
        for (var i in theJson.lists) { //循环写入下来框
          list.push(theJson.lists[i].zhuanyemingcheng)
        }
        console.log(list)
        _.setData({
          zyList: list
        })
      }
    })
  },

  bindsearch(e) {
    var _ = this;
    console.log(e.currentTarget.dataset.zy)
    _.setData({
      zhuanyemingcheng: e.currentTarget.dataset.zy,
      bindmajor: !1,
    })
  },

  //个人信息查询提交  
  seacrh(e) {
    var _ = this;
    var phone = wx.getStorageSync('52770phone')
    if (phone) {
      if (_.data.edu && _.data.zhuanyemingcheng) {
        wx.request({ //发送请求
          url: 'https://zg99.offcn.com/index/chaxun/getlist?actid=52770&callback=?', //接收url
          data: {
            xueli: _.data.edu,
            zhuanyemingcheng: _.data.zhuanyemingcheng,
            sstimes:Date.parse(Date.now()),
            limits: 200
          }, //接收参数
          success(res) {
            var jsonStr = res.data;
            jsonStr = jsonStr.replace("(", "");
            jsonStr = jsonStr.replace(")", "");
            if (typeof jsonStr != 'object') {
              jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
              var theJson = JSON.parse(jsonStr);
            }
            console.log(theJson)
            if (theJson.status == 1) {
              _.setData({
                theList: theJson.lists
              })
              console.log(_.data.theList)
              wx.pageScrollTo({
                scrollTop: 500,
                duration: 600
              })
            } else {
              wx.showToast({
                title: theJson.msg,
                icon: 'none'
              })
            }
          }
        })

      } else {
        wx.showToast({
          title: '请完整填写信息',
          icon: 'none',
          duration: 2000 //持续的时间
        })
        return false
      }
    } else {
      _.setData({
        login: 1
      })
    }

  },

  gotogwcx: function (e) {
    wx.setStorageSync('zycx', e.currentTarget.dataset.res);
    wx.navigateTo({
      url: '../zwjs/zwjs/zwjs',
    })
  },
  again: function (e) {
    wx.pageScrollTo({
      scrollTop: -500,
      duration: 600,
      theList: !1,
    })
  },
  kefu: function (e) {
    wx.setStorageSync('zycx', e.currentTarget.dataset.res);
    wx.navigateTo({
      url: '../xiaoneng/xiaoneng',
    })
  },







  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})